package com.dc.dbus.transport.commons;

import java.util.List;

public class ServerAddress {
	
	private final String[] address;
	
	private final String[] ips;
	private final int[] ports;
	
	public ServerAddress(int port) {
		
		List<String> ipList = NetUtil.sortIpList_internalIpFirst(NetUtil.getLocalIPList());
		String[] ips = ipList.toArray(new String[ipList.size()]);
		
		int[] ports = new int[ips.length];
		String[] address = new String[ips.length];
		for (int i=0; i<ports.length; i++) {
			ports[i] = port;
			address[i] = ips[i] + ":" + port;
		}
		
		this.ports = ports;
		this.ips = ips;
		this.address = address;
	}
	
	public ServerAddress(String host, int port) {
		
		this.ports = new int[] {port};
		this.ips = new String[] {host};
		this.address = new String[] {host + ":" + port};
	}

	public String[] getAddress() {
		return address;
	}

	public String[] getIps() {
		return ips;
	}

	public int[] getPorts() {
		return ports;
	}
	
	
}
